package com.project.sumup;



import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class ResultActivity extends Activity {
	private EditText SumUp;
	private Integer sumReal = 0;
	private String KEY_TOTAL = "total";
	private String KEY_DIFFICULTY = "difficulty";
	private Difficulty diff;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_result);
		SumUp = (EditText) findViewById(R.id.EtTotal);
		Intent in = getIntent();
		sumReal = Integer.parseInt(in.getStringExtra(KEY_TOTAL));
		diff = Difficulty.valueOf(in.getStringExtra(KEY_DIFFICULTY));
	}

	public void CheckTotal(View V) {
		String str = SumUp.getText().toString();
		Toast toast = new Toast(this.getApplicationContext());
		if (!str.equals("")) {
			Integer sum = Integer.parseInt(str);

			if (sum == sumReal)
				toast = Toast.makeText(this.getApplicationContext(),
						R.string.correct, Toast.LENGTH_SHORT);
			else
				toast = Toast.makeText(this.getApplicationContext(),
						R.string.wrong, Toast.LENGTH_SHORT);

		} else {

			toast = Toast.makeText(this.getApplicationContext(),
					R.string.empty, Toast.LENGTH_SHORT);
		}
		toast.show();
	}

	public void Restart(View V) {
		Intent inOut = new Intent(getApplicationContext(), NumberActivity.class);
		inOut.putExtra(KEY_DIFFICULTY, diff.toString());
		startActivity(inOut);
	}

	public void Menu(View V) {
		Intent inOut = new Intent(getApplicationContext(), MainActivity.class);
		startActivity(inOut);
	}

	public void onBackPressed() {
		Intent inOut = new Intent(getApplicationContext(), MainActivity.class);
		startActivity(inOut);
	}
}
